package com.yunhai.support.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yunhai.common.dto.PaginationVo;
import com.yunhai.common.dto.Ret;
import com.yunhai.support.entity.PhoneTextMessage;
import com.yunhai.support.entity.vo.TextMessageVo;
import com.yunhai.support.service.AliMessageService;
import com.yunhai.support.service.AliVoiceMessageService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 阿里云短信服务
 * */
@RestController
@RequestMapping("/alimenssage")
@Validated
public class AliMessageController {

    @Resource
    private AliMessageService aliMessageService;

    @Resource
    private AliVoiceMessageService aliVoiceMessageService;

    /**
     * 发送语音
     * */
    @GetMapping("/_voice")
    public Ret sendVoiceNotification(@RequestParam("phone") String phone,
                                     @RequestParam("serialNumber") String serialNumber,
                                     @RequestParam("name") String name,
                                     @RequestParam("strength") String strength,
                                     @RequestParam("energy") String energy,
                                     @RequestParam("balance") Integer balance,
                                     @RequestParam("repeatCount") Integer repeatCount) throws Exception  {

        aliVoiceMessageService.sendVoiceNotification( phone, serialNumber ,name,  strength, energy, balance, repeatCount);
        return Ret.ok();
    }

    @GetMapping("/_voice/electric")
    public Ret sendElectricVoiceNotification(
                                   @RequestParam("phone") String phone,
                                   @RequestParam("serialNumber") String serialNumber,
                                   @RequestParam("name") String name,
                                   @RequestParam("type") Integer type,
                                   @RequestParam("repeatCount") Integer repeatCount) throws Exception  {

        aliVoiceMessageService.sendElectricVoiceNotification( phone, serialNumber ,name,  type, repeatCount);
        return Ret.ok();
    }


    /**
     * 发送短信
     * */
    @GetMapping("/_code")
    public Ret sendPhoneCode(@RequestParam("phone") String phone,
                           @RequestParam("serialNumber") String serialNumber,
                           @RequestParam("nickName") String nickName,
                           @RequestParam("strength") String strength,
                           @RequestParam("energy") String energy,
                           @RequestParam("bal") Integer bal
                           ) throws Exception {

        aliMessageService.sendAlarmInfo( phone, serialNumber,nickName,strength,energy,bal );
        return Ret.ok();
    }

    /**
     * 发送短信
     * */
    @GetMapping("/_code/electric")
    public Ret sendElectricPhoneCode(@RequestParam("phone") String phone,
                           @RequestParam("serialNumber") String serialNumber,
                           @RequestParam("nickName") String nickName,
                           @RequestParam("type") Integer type,
                           @RequestParam("bal") Integer bal
    ) throws Exception {

        aliMessageService.sendElectricAlarmInfo( phone, serialNumber, nickName, type, bal );
        return Ret.ok();
    }


    /**
     * 获取短信分页列表
     * */
    @GetMapping("/_code/pagination")
    public Ret getTextMessagePagination(PaginationVo paginationVo, TextMessageVo textMessageVo) throws Exception {

        IPage page = aliMessageService.getTextMessagePagination(paginationVo, textMessageVo);
        return Ret.toPage(page);
    }


    /**
     * 获取所有短信
     * */
    @GetMapping("/_code/list")
    public Ret getTextMessageList() throws Exception {

        List<PhoneTextMessage> textMessageList = aliMessageService.getTextMessageList();
        return Ret.ok(textMessageList);
    }

}
